<!DOCTYPE html>
<html lang="en">
	<head>
	    <meta charset="UTF-8">
	    <script type="text/javascript" src="../assets/js/vue.js" ></script>
	    <title>watch</title>
	</head>
	<body>
		<h1>watch</h1>
		<div id="app">
			<p>价格 {{price}}</p>
			<p>贵不贵： {{advice}}</p>
			
			<p><button @click="add">增加</button></p>
			<p><button @click="min">减少</button></p>
		</div>
	</body>
	
	<script type="application/javascript">
		
		var app = new Vue({
			el:'#app',
			data:{
				price:100,
				advice:'太贵了'
			},
			methods:{
				add:function(){
					this.price++;
				},
				min:function(){
					this.price--;
				}
			}
//			,watch:{
//				price:function(newVal,oldVal){
//					if(newVal>=100){
//						this.advice='太贵了'
//					}else{
//						this.advice='还行吧'
//					}
//				}
//			}
		})
		
		
		//写在外面
		app.$watch('price',function(newVal,oldVal){
					if(newVal>=100){
						this.advice='太贵了'
					}else{
						this.advice='还行吧'
					}
				})
	</script>
</html>